package org.example.java_gobang.model;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

//@Mapper
//public interface UserMapper {
//    //向数据库中插入一个用户,用户用户注册
//    void insert(User user);
//    //根据用户名,查询用户信息,用户用户登录
//    User selectByName(String username);
//}

@Mapper
public interface UserMapper {
    //插入用户
    @Insert("insert into user values (null,#{username},#{password},1000,0,0)")
    Integer insert(String username,String password);

    //根据用户名 查询用户
    @Select("select * from user where username=#{username}")
    User selectByName(String username);

    //更新获胜者信息
    //总场数+1,获胜场数+1,总分数+30
    @Update("update user set totalCount = totalCount+1,winCount=winCount+1,score=score+30 where userId = #{userId}")
    void userWin(int userId);

    //更新失败者信息:
    //总场数+1,获胜场数 不变,总分数-30
    @Update("update user set totalCount = totalCount+1,score=score-30 where userId = #{userId}")
    void userLose(int userId);
}
